package com.usian.controller;

import com.usian.entity.PageResult;
import com.usian.entity.QueryPageBean;
import com.usian.entity.Result;
import com.usian.pojo.*;
import com.usian.service.EmpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("emp")
public class EmpController {
    private static final Logger log= LoggerFactory.getLogger(EmpController.class);
    @Autowired
    private EmpService empService;

    @RequestMapping("xx")
    public String toShow(){
        return "index";
    }

    @RequestMapping("findPage")
    @ResponseBody
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.debug("--------------------------------------------------------------------------");
        return empService.findPage(queryPageBean);
    }

    @RequestMapping("findDept")
    public List<Dept> findDept(){
        List<Dept>d =empService.findDept();
        return d;
    }

    @RequestMapping("findZhiWu")
    public List<ZhiWu> findZhiWu(){
        List<ZhiWu>z=empService.findZhiWu();
        return z;
    }





    @RequestMapping("/add")
    @ResponseBody
    public Result add(@RequestBody Emp emp){
            empService.add(emp);
        try {
            return new Result(true,"okk");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"no okk");
        }
    }

    @RequestMapping("/edit")
    @ResponseBody
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        try {
            return new Result(true,"okk");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"no okk");
        }
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Result delete(String eid){
        try {
            empService.delete(eid);
            return new Result(true,"okk");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"no okk");
        }

    }
}
